﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.InputDto;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;
using System.Security.Cryptography;

namespace SheepStorage.API.Controllers
{
    /// <summary>
    /// 菜单模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuListController : ControllerBase
    {
      private readonly  IMenuListService service;
  
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public MenuListController(IMenuListService service)
        {
            this.service = service;
        }
        /// <summary>
        /// 获取菜单信息列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task< Results< List<MenuList>>> GetMenuLists(string? MenuName)
        {
            var list = await service.GetMenuLists(MenuName);
            return Results<List<MenuList>>.DataResult(list);
        }



             /// <summary>
             /// 添加菜单
             /// </summary>
             /// <param name="input"></param>
             /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddMenus(MenuList input)
        {
            var res = await service.AddMenus(input);
            return Results<int>.DataResult(res);
        }




        /// <summary>
        /// 删除菜单-物理删除
        /// </summary>
        /// <param name="menuId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DeleteMenuList(List<int> menuId)
        {
            var res = await service.DeleteMenuList(menuId);
            return Results<int>.DataResult(res);
        }



        /// <summary>
        /// 菜单反填信息
        /// </summary>
        /// <param name="menuId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<MenuList>> GetMenuListById(int menuId)
        {

            var entity = await service.GetMenuListById(menuId);
            return Results<MenuList>.DataResult(entity);
        }



        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> UpdateMenuList(MenuList input)
        {
            var res = await service.UpdateMenuList(input);
            return Results<int>.DataResult(res);
        }













        /// <summary>
        /// 级联方法显示菜单
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task< Results<List<MenuListCascaders>>> GetMenuListCascaders(int pid = 0)
        {
            var list=  service.GetMenuListCascaders(pid);
            return Results<List<MenuListCascaders>>.DataResult(list);
        }




        /// <summary>
        /// 批量添加菜单权限
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task< Results<int>> AddMenuList(MenuPermissionInput input)
        {
            var list =await service.AddMenuList(input);
            return Results<int>.DataResult(list);
        }


        /// <summary>
        /// 列表查看菜单权限
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task< Results<object>> GetMenuPermissions()
        {
            var list =await service.GetMenuPermissions();
            return Results<object>.DataResult(list);
        }






    }
}
